package com.book.settings.controller;

import com.book.common.Result;
import com.book.settings.pojo.Admin;
import com.book.settings.pojo.Login;
import com.book.settings.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/settings/admin/tologin.do")
    public Result Login( @RequestBody Login login){
        Admin admin = loginService.Login(login);
        if(admin==null){
            return Result.error("用户名或密码错误");
        }
        return Result.success(admin,1);
    }

    @GetMapping ("/settings/exit.do")
    public Result Exist(HttpServletRequest request){
        request.getSession().invalidate();
        return Result.success();
    }
}
